#include "DCAComputation.h"

////////////////////////////////////////////////////////
// Assemble
////////////////////////////////////////////////////////

void DCABasic::assemble(){                
        RSIM::DCAAssembly3D *Asm = mbs3D->Asm_;
        mbs3D->n_assemble_Opt(Asm[parent_id],Asm[child_id],Asm[asm_id],calcH2,calcH1);        
}

void DCARoot::assemble(){         
        RSIM::DCAAssembly3D *Asm = mbs3D->Asm_;
        mbs3D->n_assemble_Opt(Asm[parent_id],Asm[child_id],Asm[asm_id],calcH2,calcH1);
//         Asm[asm_id].dca_.displayH1();
//         Asm[asm_id].dca_.displayH2();
}

void DCAABA::assemble(){        
        mbs3D->n_formInboardEOM(start_id,end_id);
//         cout<<start_id<<"\t"<<end_id<<"\t"<<calcH1<<endl;
//         cin.get();
        if(calcH1){
                mbs3D->n_calcDCAHandleEquationsUsingABA_Opt(start_id,end_id,asm_id,calcH2);
//                 cout<<"Bhalerao:"<<start_id<<"\t"<<end_id<<"\t"<<calcH1<<endl;                
//                 cin.get();
        }
        else{
                mbs3D->n_calcDCAHandleEquationsUsingLillyOrin_Opt(start_id, end_id,asm_id);
//                 cout<<"Lilly:"<<start_id<<"\t"<<end_id<<endl;
//                 cin.get();
        }
        
}

void DCA::assemble(){        
        mbs3D->n_formDCAHandleEquations_Opt(start_id,end_id);        
        mbs3D->n_calcDCAHandleEquationsUsingDCA(start_id,end_id,start_asm,calcH2);        
}

void DCAABA::kinAssembly(){                
        mbs3D->assembleKinematicSweep(kin_startid,kin_endid);        
}


////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
// Solve
////////////////////////////////////////////////////////
void DCARoot::solve(){        
        if(calc_pinvjac){
                mbs3D->solveSystemHandleEquationsCase_OpControl();
                mbs3D->disassembleDCAAssembly_Opt(asm_id,true,true);
        }
        else{
                mbs3D->solveSystemHandleEquationsCaseI_Opt();
                mbs3D->disassembleDCAAssembly_Opt(asm_id,calcH2);
        }
}

void DCABasic::solve()     // the local solve operation    
{               
        mbs3D->disassembleDCAAssembly_Opt(asm_id,calcH2,calc_pinvjac);
}

void DCAABA::solve()     // the local solve operation    
{        
        mbs3D->disassembleABAAssembly_Opt(asm_id,calcH2,calc_pinvjac);
}

void DCA::solve()     // the local solve operation    
{        
        mbs3D->disassembleDCAAssembly_Opt(dis_start,dis_end,calcH2);
}

void DCARoot::kinSolve()     // the local solve operation    
{                        
        mbs3D->setKinematicBoundaryConditions();        
}

void DCAABA::kinSolve()  // the local assembly operation
{         
        mbs3D->disassembleKinematicSweep(kin_startid,kin_endid);

}

////////////////////////////////////////////////////////

void DCAABA::comp_null(){                
        mbs3D->calcNullSpaceProjectionMatrix(start_id,end_id);                
}